package com.ljwy.gun;

import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;


import androidx.annotation.RequiresApi;


import com.ljwy.gun.bean.DaKaInfo;
import com.ljwy.gun.utils.cache.ACacheHelper;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

public class ClockAdapter extends BaseViewAdapter<DaKaInfo.DataBean> {

    public ClockAdapter(Context context, List<DaKaInfo.DataBean> list) {
        super(context, list);
    }

    @RequiresApi(api = Build.VERSION_CODES.M)
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            view = View.inflate(context, R.layout.adapter_clock, null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        DaKaInfo.DataBean info = list.get(i);
        holder.cpNameTv.setText(info.getUid());
        holder.noTv.setText(ACacheHelper.getInstance().getString("CPNAME",""));
        holder.whenTv.setText(info.getWhen());
        holder.passTv.setText(info.getCp_name());
        if (info.isPass()){
            holder.isPass.setText("成功");
            holder.isPass.setTextColor(Color.GREEN);
        }else {
            holder.isPass.setText("未上传");
            holder.isPass.setTextColor(Color.RED);
        }
        return view;
    }

    static
    class ViewHolder {
        @BindView(R.id.no_tv)
        TextView noTv;
        @BindView(R.id.cp_name_tv)
        TextView cpNameTv;
        @BindView(R.id.when_tv)
        TextView whenTv;
        @BindView(R.id.pass_tv)
        TextView passTv;

        @BindView(R.id.is_pass)
        TextView isPass;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
